/*
 * Project: GraphicLCD Arduino Library
 *
 * Header Name: GraphicLCD.h
 * Created on: 18/AUG/2009
 *
 * Copyright (c) 2009 Tiago Barros.
 * All rights reserved.
 *
 * Code contributions from: 
 *   - Markos Kyritsis (PhillipsLCD lib)
 *   - James Lynch (Nokia 6100 LCD Display Driver)
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, 
 *   this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice, 
 *   this list of conditions and the following disclaimer in the documentation 
 *   and/or other materials provided with the distribution.
 * - Neither the name of tiagobarros.org nor the names of its contributors may be 
 *   used to endorse or promote products derived from this software without 
 *   specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * REVISION HISTORY:
 *
 * Date         Author(s)
 * Version      Headline
 * ===========  ==============================================================
 * 18/AUG/2009  Tiago Barros
 * 00.10        Initial Creation
 * ===========  ==============================================================
 *
 *
 *
 * ---------------------------------------------------------------------------
 *  General Description: This file defines the GraphicLCD class. 
 *  This class provides the graphic primitives for use the 128x128 Graphic LCD
 *  with Philips PCF8833 Controller. This LCD is found on some Nokia phones 
 *  like 6560, 3105, 3120, 3200, 3205, 5140, 6030, 6225, 6585, 7210, 7250 
 *  and 7250i. Sparkfun also sels this LCD on the following link:
 *  http://www.sparkfun.com/commerce/product_info.php?products_id=569
 *
 *  LCD with Phillips controller has a brown pcb. LCD with Epson controller
 *  has a green PCB.
 *  This library does not work with Epson S1D15G10 controller yet.
 * ---------------------------------------------------------------------------
 */
#ifndef GRAPHICLCD_H
#define GRAPHICLCD_H
#define TIAGOBARROS_ORG_LCD_SHIELD


// include avr registers constants 
#include <avr/pgmspace.h>


#ifdef TIAGOBARROS_ORG_LCD_SHIELD

// LCD arduino pins on tiagobarros.org LCD shield
#define  LCD_RESET  2  
#define  LCD_SCLK   4  

#define  LCD_CS     7  
#define  LCD_SDATA  8  // SDATA is the pin 0 of PORTB

#else
#error "You must define the arduino pins that you are using. Please define the following constants: LCD_RESET, LCD_SCLK, LCD_CS and LCD_SDATA."
#endif

// LCD constants 
// add width, height, etc - verify difference from creating a const attribute

// defining the colors for the Phillips controller
enum
{
        /* colors are in the following form:
           0     B     G     R
           0000  ----  ----  ----
           
           4 bits per pixel, BGR orientation
        */
        
	/* define a special value to be treated as transparent when used as
	   the background color (when outputting text); technically all byte
	   values correspond to an actual color, but we'll override this
	   very dark green for that purpose */
	LCD_CLR_TRANSP  	= 0x0010, // 0000 0000 0001 0000

	LCD_CLR_BLACK		= 0x0000, // 0000 0000 0000 0000
	LCD_CLR_WHITE		= 0x0fff, // 0000 1111 1111 1111

	LCD_CLR_RED		= 0x000f, // 0000 0000 0000 1111
	LCD_CLR_GREEN		= 0x00f0, // 0000 0000 1111 0000 
	LCD_CLR_BLUE		= 0x0f00, // 0000 1111 0000 0000 

	LCD_CLR_MED_RED		= 0x000C, // 0000 0000 0000 1100
	LCD_CLR_MED_GREEN	= 0x00C0, // 0000 0000 1100 0000
	LCD_CLR_MED_BLUE	= 0x0C00, // 0000 1100 0000 0000

	LCD_CLR_DK_RED		= 0x0008, // 0000 0000 0000 1000
	LCD_CLR_DK_GREEN	= 0x0080, // 0000 0000 1000 0000
	LCD_CLR_DK_BLUE		= 0x0800, // 0000 1000 0000 0000

	LCD_CLR_YELLOW		= 0x00ff, // 0000 0000 1111 1111
	LCD_CLR_ORANGE		= 0x008f, // 0000 0000 1111 1000
	LCD_CLR_BROWN		= 0x0077, // 0000 0000 0111 0111

	LCD_CLR_MAGENTA		= 0x0f0f, // 0000 1111 0000 1111
	LCD_CLR_PURPLE		= 0x0f0c, // 0000 1111 0000 1000
	LCD_CLR_CYAN		= 0x0ff0, // 0000 1111 1111 0000
};

// library interface description
class GraphicLCD
{
    public:
        GraphicLCD();
        void Init();
        void Clear(int color);

        void PutPixel(int x, int y, unsigned int color);

        void FillRect(int x1, int y1, int x2, int y2, int color);


        // functions to: set font, write char, write string, 
        //               draw line, draw arc, draw elipse, fill arc, fill elipse, 
        //               read bitmap, draw bitmap

    private:
        inline void WriteCommand(unsigned char command) { Write(command, 0); }
        inline void WriteData(unsigned char data) { Write(data, 1); }
        void Write(unsigned char byte_to_write, unsigned char data_or_command);

};

extern GraphicLCD LCD;

#endif

